import { BaseWindow } from "../../../component/window/BaseWindow";
import { ItemData } from "../../resource/info/ItemData";
import { EMergeType } from "../../../../Message/Public/EMergeType";
import { Language } from "../../../../extend/language/Language";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { Cache } from "../../cache/Cache";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { GButton } from "../../../../com/mui/controls/GButton";
import { StringHelper } from "../../../../com/gengine/utils/StringHelper";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { _mergeType } from "../../../../this/_mergeType";
type int = number;
//class WingFusionAlertWindow
    
    export  class WingFusionAlertWindow extends BaseWindow
    {
        constructor()
        {
            super();
            if (WingFusionAlertWindow._instance) 
            {
                throw new Error("WingFusionAlertWindow 单例");
            }
            this.init();
            return;
        }

        public WingFusionAlertWindow.get mainItemData(): ItemData
        {
            return this._mainItemData;
        }

        public set mainItemData(arg1: ItemData)
        {
            this._mainItemData = arg1;
            return;
        }

        public set mergeType(arg1: int)
        {
            this._mergeType = arg1;
            if (this._mergeType != EMergeType._EMergeTypeWing) 
            {
                if (this._mergeType == EMergeType._EMergeTypeFashion || this._mergeType == EMergeType._EMergeTypeWeaponFashion) 
                {
                    this._inputTipTxt.htmlText = Language.getString(36214);
                }
                else if (this._mergeType != EMergeType._EMergeTypeFootprint) 
                {
                    if (this._mergeType != EMergeType._EMergeTypeBubble) 
                    {
                        if (this._mergeType != EMergeType._EMergeTypeSurround) 
                        {
                            if (this._mergeType != EMergeType._EMergeTypeWaistBelt) 
                            {
                                if (this._mergeType == EMergeType._EMergeTypeElf) 
                                {
                                    this._inputTipTxt.htmlText = Language.getString(74728);
                                }
                            }
                            else 
                            {
                                this._inputTipTxt.htmlText = Language.getString(74708);
                            }
                        }
                        else 
                        {
                            this._inputTipTxt.htmlText = Language.getString(71468);
                        }
                    }
                    else 
                    {
                        this._inputTipTxt.htmlText = Language.getString(71451);
                    }
                }
                else 
                {
                    this._inputTipTxt.htmlText = Language.getString(71410);
                }
            }
            else 
            {
                this._inputTipTxt.htmlText = "<textFormat leading=\'5\'>" + HTMLUtil.addColor(Language.getString(36112), "#B1efff") + "</textFormat>";
            }
            return;
        }

        /* internal  */init(): void
        {
            this.setSize(300, 200);
            this.titleHeight = 28;
            this.title = Language.getString(54049);
            this._bg = ObjCreate.createBg(17, 39, 264, 128, this);
            this._tipTxt = ObjCreate.createTextField("", 20, 50, 260, 50, this, new GTextFormat(FontUtil.songtiName, 14, 11661311));
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._tipTxt.multiline = true;
            this._inputTipTxt = ObjCreate.createTextField("", 0, 130, 300, 50, this, new GTextFormat(FontUtil.songtiName, 14, 11661311));
            this._inputTipTxt.multiline = true;
            this._inputTipTxt.htmlText = "<textFormat leading=\'5\'>" + HTMLUtil.addColor(Language.getString(36112), "#B1efff") + "</textFormat>";
            this._inputTipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._delInput = ObjCreate.createGTextInput(80, 170, 135, 20, this);
            this._delInput.maxChars = 6;
            this._delInput.restrict = "A-z";
            this._okBtn = ObjCreate.createGButton(Language.getString(54055), 60, 130, 70, 27, this);
            this._okBtn.name = "ok";
            this._cancelBtn = ObjCreate.createGButton(Language.getString(54052), 160, 130, 70, 27, this);
            this._cancelBtn.name = "cancel";
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            return;
        }

        public WingFusionAlertWindow.get deputyItemData(): ItemData
        {
            return this._deputyItemData;
        }

        public set deputyItemData(arg1: ItemData)
        {
            var loc1=null;
            var loc2=false;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            this._deputyItemData = arg1;
            if (arg1) 
            {
                loc1 = "";
                loc2 = Cache.instance.wardrobe.isMergeLevelAdd(this._mergeType, this._deputyItemData);
                loc3 = "";
                loc4 = 0;
                loc5 = "";
                if (loc2) 
                {
                    loc3 = Language.getString(36215);
                    loc4 = 1;
                }
                else 
                {
                    loc3 = Language.getString(36216);
                }
                if (this._mergeType != EMergeType._EMergeTypeWing) 
                {
                    if (this._mergeType == EMergeType._EMergeTypeFashion || this._mergeType == EMergeType._EMergeTypeWeaponFashion) 
                    {
                        loc1 = Language.getString(36204);
                        loc5 = Language.getString(36200);
                    }
                    else if (this._mergeType != EMergeType._EMergeTypeFootprint) 
                    {
                        if (this._mergeType != EMergeType._EMergeTypeBubble) 
                        {
                            if (this._mergeType != EMergeType._EMergeTypeSurround) 
                            {
                                if (this._mergeType != EMergeType._EMergeTypeWaistBelt) 
                                {
                                    if (this._mergeType == EMergeType._EMergeTypeElf) 
                                    {
                                        loc1 = Language.getString(74723);
                                        loc5 = Language.getString(74721);
                                    }
                                }
                                else 
                                {
                                    loc1 = Language.getString(74703);
                                    loc5 = Language.getString(74701);
                                }
                            }
                            else 
                            {
                                loc1 = Language.getString(71463);
                                loc5 = Language.getString(71461);
                            }
                        }
                        else 
                        {
                            loc1 = Language.getString(71446);
                            loc5 = Language.getString(71444);
                        }
                    }
                    else 
                    {
                        loc1 = Language.getString(71405);
                        loc5 = Language.getString(71402);
                    }
                }
                else 
                {
                    loc1 = Language.getString(36115);
                    loc5 = Language.getString(36201);
                }
                loc1 = Language.getStringByParam(36217, loc1, ItemsUtil.getItemName(arg1), loc5, loc4, loc3);
                this._tipTxt.htmlText = loc1;
            }
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=arg1.target as GButton;
            if (this._deputyItemData) 
            {
                if (loc1.name != "ok") 
                {
                    this.hide();
                }
                else 
                {
                    if (this._mode == WingFusionAlertWindow.ValidateMode) 
                    {
                        loc2 = this._delInput.text.toLocaleLowerCase();
                        if (StringHelper.getCharLength(StringHelper.trim(loc2)) == 0) 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(54054));
                            return;
                        }
                        if (loc2 != "delete") 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(54054));
                            return;
                        }
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.WingGoMerge, {"wingUid1": this._mainItemData.uid, "wingUid2": this._deputyItemData.uid, "posType1": this._mainItemData.posType, "posType2": this._deputyItemData.posType, "mergeType": _mergeType}));
                    this.hide();
                }
            }
            return;
        }

        public set mode(arg1: int)
        {
            this._mode = arg1;
            if (arg1 != WingFusionAlertWindow.NormalMode) 
            {
                this.setSize(300, 250);
                this._bg.height = 198;
                this._okBtn.y = 200;
                this._cancelBtn.y = 200;
                this._inputTipTxt.visible = true;
                this._delInput.visible = true;
            }
            else 
            {
                this.setSize(300, 170);
                this._bg.height = 118;
                this._okBtn.y = 120;
                this._cancelBtn.y = 120;
                this._inputTipTxt.visible = false;
                this._delInput.visible = false;
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._delInput.text = "";
            return;
        }

        public static get instance(): WingFusionAlertWindow
        {
            if (WingFusionAlertWindow._instance == null) 
            {
                WingFusionAlertWindow._instance = new WingFusionAlertWindow();
            }
            return WingFusionAlertWindow._instance;
        }

        /* internal */ /* var */_mode: int;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_delInput: GTextInput;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_inputTipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_delTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_mainItemData: ItemData;

        /* internal */ /* var */_deputyItemData: ItemData;

        /* internal */ /* var */_mergeType: int=1;

        public static /* var */NormalMode: int=0;

        public static /* var */ValidateMode: int=1;

        /* internal */ static /* var */_instance: WingFusionAlertWindow;
    }

            WingFusionAlertWindow.NormalMode = 0;
            WingFusionAlertWindow.ValidateMode = 1;
        